package com.dks.controller;


import com.dks.models.Diary;
import com.dks.repository.IDiaryRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("diary")
@RestController
public class DiaryController{

    private IDiaryRepository diaryRepository;

    @Autowired
    public DiaryController(final IDiaryRepository diaryRepositoryIn){
        this.diaryRepository = diaryRepositoryIn;
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取教师日记列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: teacherId 老师id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-teacher-diary-list")
    public ResultModel<Object> getCourseTeacherList(Integer teacherId, Integer pageNum, Integer pageSize) {
        if (null == teacherId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "teacherId");
        }
        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return diaryRepository.getCourseTeacherList(teacherId, pageNum,pageSize);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取教师日记详情
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: diaryId 日记id
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-teacher-diary-info")
    public ResultModel<Object> getCourseTeacherInfo(Integer diaryId,Integer userId) {
        if (null == diaryId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "diary");
        }
        if (null == userId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "userId");
        }
        return diaryRepository.getCourseTeacherInfo(diaryId,userId);
    }


    /**
     * @Author: Ah Nan
     * @Description: 发布日记
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: diaryId 日记id
     * @return:
     * @throw: 请描述异常信息
     */
    @PostMapping("add-teacher-diary")
    public ResultModel<Object> addTeacherDiary(@RequestBody Diary diary) {
        if (null == diary.getTeacherId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "teacherId");
        }
        if (null == diary.getDiaryCommend()||diary.getDiaryCommend().isEmpty()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "diaryCommend");
        }
        return diaryRepository.addTeacherDiary(diary);
    }



}
